﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Utilities.Text
{
    public class TextStream : Stream
    {
        public Stream BaseStream { get; set; }

        private StreamReader streamReader;
        private StreamWriter streamWriter;

        public TextStream(Stream baseStream)
        {
            BaseStream = baseStream;
            streamReader = new StreamReader(baseStream);
            streamWriter = new StreamWriter(baseStream);
        }

        public override bool CanRead
        {
            get
            {
                return BaseStream.CanRead;
            }
        }
        public override bool CanWrite
        {
            get
            {
                return BaseStream.CanWrite;
            }
        }
        public override bool CanSeek
        {
            get
            {
                return BaseStream.CanSeek;
            }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return BaseStream.Read(buffer, offset, count);
        }
        public override void Write(byte[] buffer, int offset, int count)
        {
            BaseStream.Write(buffer, offset, count);
        }
        public override long Seek(long offset, SeekOrigin origin)
        {
            return BaseStream.Seek(offset, origin);
        }

        public override void Flush()
        {
            BaseStream.Flush();
        }

        public override long Position
        {
            get
            {
                return BaseStream.Position;
            }
            set
            {
                BaseStream.Position = value;
            }
        }
        public override long Length
        {
            get
            {
                return BaseStream.Length;
            }
        }
        public override void SetLength(long value)
        {
            BaseStream.SetLength(value);
        }

        public string ReadLine()
        {
            return streamReader.ReadLine();
        }
        public string ReadToEnd()
        {
            return streamReader.ReadToEnd();
        }

        // TODO: Override every overload of Write()
        public void WriteLine(object value)
        {
            streamWriter.WriteLine(value);
        }
    }
}